package com.blb.service.impl;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blb.entity.User;
import com.blb.entity.Userrole;
import com.blb.mapper.UserMapper;
import com.blb.mapper.UserroleMapper;
import com.blb.service.IUserService;
import com.mysql.jdbc.StringUtils;

@Service
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserMapper userMapper;
	
	@Autowired
	private UserroleMapper userroleMapper;
	
	@Override
	public String add(User user, String roles) throws IOException {
		//保存用户表
		userMapper.insertSelective(user);
		
		//保存用户角色表
		if (!StringUtils.isNullOrEmpty(roles)) {
			String[] roleArr = roles.split(",");
			for (String role : roleArr) {
				Userrole userrole = new Userrole();
				userrole.setRoleId(role);
				userrole.setUserId(user.getId());
				userroleMapper.insert(userrole);
			}
		}
		return "";
	}

}
